﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KNXObjects
{
    public class ValueObject : GenericObjectBase<double>
    {
        #region ObjectBase Implementations

        public override string DataPointEISName
        {
            get { return "EIS5"; }
        }

        public override string DataPointID
        {
            get { return "9.xxx"; }
        }

        public override string ToString()
        {
            return Value.ToString("#.########");
        }

        public override double Value
        {
            get
            {
                return base.Value;
            }
            set
            {
                if (value > 670760.96 || value < -671088.64)
                    throw new ApplicationException("ValueObject: Value must be between -671088.64 and 670760.96. Val : " + value);

                base.Value = value;
            }
        }
        public override void SetValue(string value)
        {
            double val;
            if (!double.TryParse(value, out val))
                throw new ApplicationException("ValueObject: cannot parse value to double. Val : " + value);
            Value = val;
        }

        #endregion

        #region ctor

        public ValueObject(string id, string address, string name, string flags)
            : base(id, address, name, flags)
        {
        }

        public ValueObject(string value)
        {
            SetValue(value);
        }

        #endregion
    }
}
